package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/*
  自己的配置类，误被springboot导入了！如何排除！

    1. 少了配置类核心参数，我们就添加参数 【一定使用配置类】
    2. 可以排除配置类，不让他生效 [一定不用]
        @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) [springboot的自动配置类]
        @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = MinioConfiguration.class))
    3. 可能用 满足我们配置minio的参数就会使用
        @ConditionalOnProperty(prefix = "minio", name = "username")
 */

//代表是配置类
@Configuration
//扫描读取外部配置文件
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(prefix = "minio", name = "username")
public class MinioConfiguration {
    //注入
    @Autowired
    private MinioProperties minioProperties;
    //实现minio登录功能，使其只用登陆一次即可使用，不用每次登陆
    @Bean
    public MinioClient minioClient(){
        return  MinioClient.builder()
                .endpoint(minioProperties.getEndPoint())
                .credentials(minioProperties.getUsername(), minioProperties.getPassword())
                .build();
    }
}
